package jdmx.admin.service;

import java.sql.SQLException;
import java.util.Hashtable;
import java.util.List;

import jdmx.admin.common.HandlerSql;
import jdmx.framework.service.StaticContent;
import jdmx.library.da.DataTable;
import jdmx.library.da.Entity;
import jdmx.library.da.SqlStatement;

public class DaoSqlStatement extends DaoAdmin {
	
	@Override
	public void loadStaticContent() {
		String sql =  "";
		sql += "select SS.id, SS.name as statementName, SS.sql, E.name as entityName ";
		sql += "from SqlStatement SS left join Entity E on SS.entityId = E.id";
		DataTable dataTable = null;
		try {
			dataTable = db.fetch(new SqlStatement(sql));
		} catch (SQLException e1) {
		}
		
		if (dataTable != null) {
			List<Entity> entityList = mapper.getEntityList(dataTable, null);
			Hashtable<String, Object> ht = new Hashtable<String, Object>(100);
			for (Object entity: entityList) {
				HandlerSql statement = (HandlerSql)entity;
				String key = statement.getEntityName() + "." + statement.getStatementName(); 
				ht.put(key, statement);
			}
			
			StaticContent.putHt("SqlStatement", ht);
		}
	}

}
